<?php $start = microtime(TRUE); ?>
<?php include "userfunctions.php"; ?>
<html>
<head>
<title><?php title($title); ?> :Submit a Quote</title>
<?php css($css); ?>
</head>
<body><center>
<?php qheader(); ?>
<font face="arial" size="3">
<?php showlinks(); ?></center>
<div id="body">
<?php

  $var = @$_GET['q'] ;
  $trimmed = trim($var); 
  $limit=100; 

if ($trimmed == "")
  {
	die("Please enter a search term or terms and try again.");
  }

if (!isset($var))
  {
	die("Please enter a search term or terms and try again.");
  }

startsql();
$query = "select * from quotes where quote like \"%$trimmed%\"  
  order by id DESC"; 
 $numresults=mysql_query($query) or die(mysql_error());
 $numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
 echo 'Woah - nothing we have matches your sense of humor! Your search for "'.$trimmed.'" returned nothing! Please try again.';
  }
// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

// begin to show results set
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $quote = $row["quote"];

  echo "<br><br><a href=\"showquote.php?q=".$row['id']."\">(Fish # ".$row['id'].")</a> $quote" ;
  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "<p align=\"left\"><a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a></p>";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo "<p align=\"right\"><a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a></p>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  
?>


</div></body>


</div>
<center>
<br><br><font size="2">
<?php footer(); ?>
<?php
$finish = microtime(TRUE);
$total_time = round(($finish - $start), 4);
echo '<br>Page generated in '.$total_time.' seconds.'."\n"; 
?>
</font>
</center>
</html>

